package com.hunau.web.controller.terminal;

import java.util.List;

import com.hunau.system.domain.TbIotype;
import com.hunau.system.service.ITbIotypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hunau.common.annotation.Log;
import com.hunau.common.enums.BusinessType;
import com.hunau.common.core.controller.BaseController;
import com.hunau.common.core.domain.AjaxResult;
import com.hunau.common.utils.poi.ExcelUtil;
import com.hunau.common.core.page.TableDataInfo;

/**
 * 物联网数据采集类型Controller
 * 
 * @author ruoyi
 * @date 2020-03-20
 */
@Controller
@RequestMapping("/system/iotype")
public class TbIotypeController extends BaseController
{
    private String prefix = "terminal/iotype";

    @Autowired
    private ITbIotypeService tbIotypeService;

    @RequiresPermissions("system:iotype:view")
    @GetMapping()
    public String iotype()
    {
        return prefix + "/iotype";
    }

    /**
     * 查询物联网数据采集类型列表
     */
    @RequiresPermissions("system:iotype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbIotype tbIotype)
    {
        startPage();
        List<TbIotype> list = tbIotypeService.selectTbIotypeList(tbIotype);
        return getDataTable(list);
    }

    /**
     * 导出物联网数据采集类型列表
     */
    @RequiresPermissions("system:iotype:export")
    @Log(title = "物联网数据采集类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbIotype tbIotype)
    {
        List<TbIotype> list = tbIotypeService.selectTbIotypeList(tbIotype);
        ExcelUtil<TbIotype> util = new ExcelUtil<TbIotype>(TbIotype.class);
        return util.exportExcel(list, "iotype");
    }

    /**
     * 新增物联网数据采集类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物联网数据采集类型
     */
    @RequiresPermissions("system:iotype:add")
    @Log(title = "物联网数据采集类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbIotype tbIotype)
    {
        return toAjax(tbIotypeService.insertTbIotype(tbIotype));
    }

    /**
     * 修改物联网数据采集类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbIotype tbIotype = tbIotypeService.selectTbIotypeById(id);
        mmap.put("tbIotype", tbIotype);
        return prefix + "/edit";
    }

    /**
     * 修改保存物联网数据采集类型
     */
    @RequiresPermissions("system:iotype:edit")
    @Log(title = "物联网数据采集类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbIotype tbIotype)
    {
        return toAjax(tbIotypeService.updateTbIotype(tbIotype));
    }

    /**
     * 删除物联网数据采集类型
     */
    @RequiresPermissions("system:iotype:remove")
    @Log(title = "物联网数据采集类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbIotypeService.deleteTbIotypeByIds(ids));
    }
}
